import { defineConfig } from "vite"
import react from "@vitejs/plugin-react"
import { resolve } from "path"
import { viteMockServe } from "vite-plugin-mock"

const pathSrc = resolve(__dirname, "src")
const envPath = resolve(__dirname, "src", ".env")

// https://vitejs.dev/config/
export default defineConfig({
    build: {
        outDir: 'dist',
        assetsDir: 'assets',
        rollupOptions: {
          input: 'index.html', // 指定入口 HTML 文件
        },
    },
    base: './', // 设置基本路径
    assetsInclude: ["**/*.bpmn"],
    css: {
        preprocessorOptions: {
            less: {
                javascriptEnabled: true,
                modifyVars: {},
            },
        },
    },
    plugins: [
        react({
            jsxImportSource: "@emotion/react",
            babel: {
                presets: ["@emotion/babel-preset-css-prop"],
            },
        }),
        // mock server 配置
        viteMockServe({
            mockPath: "./mock", // mock文件存放的位置
        }),
    ],
    resolve: {
        alias: [
            {
                find: "@/",
                replacement: `${pathSrc}/`,
            },
        ],
    },
    server: {
        proxy: {
            "/api": {
                target: "http://127.0.0.1:8888/api",
                changeOrigin: true,
                rewrite: path => path.replace(/^\/api/, ""),
            },
            "/login": {
                target: "http://127.0.0.1:8888/login",
                changeOrigin: true,
                rewrite: path => path.replace(/^\/login/, ""),
            },
        },
    },
})
